<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>T_order_goods信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top:1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<div class="" style="margin-right:2px;padding-right:1px;">

    <!--------------------------查询条件表格  start------------------------------->
    <form class="form-horizontal" name="form1" id="form1">
        <!-- 查询面板 -->
        <div class="panel panel-primary" id="cxDiv">
            <!-- Default panel contents -->
            <div class="panel-heading  " >
                <i class='icon-filter'></i>&nbsp;订单管理-->重新打印
                <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded"  onclick="Search(0)"><i class="icon-search"></i>&nbsp;查询</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"  > <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton" >&nbsp;<span id="qhDiv" class="icon-chevron-up"></span>&nbsp;</button>
            <input type="hidden" name="process_code" id="process_code" value="<%= request.getParameter("process_code")!=null?request.getParameter("process_code"):""%>">
        </span>
            </div>
            <div class="panel-body" id="shDiv" class="panel-collapse collapse in">

                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-6">客户名称</label>
                        <div class="col-xs-6">
                            <input name="buyer_company_name" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-6">供应商</label>
                        <div class="col-xs-6">
                            <input name="saller_company_name" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-5">PO/订单号</label>
                        <div class="col-xs-7">
                            <input name="saller_tel" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-5">CPN/物料编码</label>
                        <div class="col-xs-7">
                            <input name="buyer_tel" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-5">MPN/规格型号</label>
                        <div class="col-xs-7">
                            <input name="saller_company_address" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-6"> BRAND/品牌</label>
                        <div class="col-xs-6">
                            <input name="ext2" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-6"> 盘数</label>
                        <div class="col-xs-6">
                            <input name="good_num" id="good_num" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-5">创建开始时间</label>
                        <div class="col-xs-7">
                            <input name="startdate" id="startdate" type="text" class="form-control"  onclick='SelectDate(this)' readonly='true'>
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-5">创建结束时间</label>
                        <div class="col-xs-7">
                            <input name="enddate" id="enddate" type="text" class="form-control"  onclick='SelectDate(this)' readonly='true'>
                        </div>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="form-group">
                        <label class="control-label col-xs-6"> 状态</label>
                        <div class="col-xs-6">
                            <select name="status" id="status" class="form-control">
                                <option value="">全部</option>
                                <option value="0">未扫描</option>
                                <option value="1">部分扫描</option>
                                <option value="2">已扫描</option>
                            </select>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </form>
    <!--------------------------查询条件表格end------------------------------------->

    <!--------------------------信息列表：带表格面板  start--------------------------------->
    <div class="panel panel-primary">
        <div class="panel-heading clearfix" >
            <i class='icon-reorder'></i>&nbsp; 数据列表
            <span class="text-right pull-right ">
            <!--
            <a href="<%=basePath%>t_order_goods/toT_order_goodsCurd?oplx=add" class="text-danger"><i class='icon-plus'></i>&nbsp;新增</a>
            <a href="#" onclick="toEdits()" class="text-danger"><i class='icon-pencil'>&nbsp;修改</i></a>
            <a href="#" onclick="toViews()"  class="text-danger"><i class='icon-table'></i>&nbsp;查看</a>
            <a href="#" onclick="getDel()" class="text-danger"><i class='icon-minus'></i>&nbsp;删除</a>&nbsp;
            -->
  <%
      String process_code = request.getParameter("process_code");
      if(null!=process_code &&  !"".equalsIgnoreCase(process_code) && process_code.equalsIgnoreCase("smdy")){
          //out.print("process_code="+process_code);
  %>
                <!--<a href="<%=basePath%>t_order_goods/toT_order_goodsSMDY?oplx=add" class="text-danger"><i class='icon-print'></i>&nbsp;进入扫描</a>-->
	  <%}%>

            <a href="#" onclick="Search(0)" class="text-danger btn-sm"><i class='icon-refresh'></i>&nbsp;刷新</a>&nbsp;&nbsp;
            <a href="#" onclick="showOrHidden()" class="text-danger btn-sm"><span id="fsDiv" class='glyphicon glyphicon-resize-full'></span></a>
	     </span>
        </div>
        <div class="panel-body">
            <p>每页显示<select id="pageSize" class=" label-primary" onchange="Search(0)">
                <option value="10" >10</option>
                <option value="20">20</option>
                <option value="30">30</option>
                <option value="50" selected>50</option>
                <option value="100" >100</option>
            </select>条记录，&nbsp;&nbsp;&nbsp;&nbsp;共有记录：<span id="totalCount" class="label label-primary">0</span> 条，总页数：<span id="totalPageNo" class="label label-primary">0</span>页。
            </p>
            <table id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
                <thead id="grid_head">
                <tr>
                    <!---->
                    <th onclick="" class="table-checkbox" ><input class="group-checkable" name="batchSelectedAll" id="batchSelectedAll" type="checkbox" onclick="selectAll()"></th>

                    <th onclick="sortTableT.sort('grid',0,'String')"> 序号</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">客户名称</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">PO/订单号</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">CPN/物料编</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">MPN/规格型号</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">QTY/数量</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">BRAND/品牌</th>
                    <th onclick="sortTableT.sort('grid',0,'String')">供应商</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 盘数</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 已扫描盘数</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 辅助出货数量</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 创建者</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 创建时间</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 更新者</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 更新时间</th>
                    <th onclick="sortTableT.sort('grid',0,'String')"> 状态</th>
                    <th style="width:50px">操作</th>
                </tr>
                </thead>
                <tbody id="grid_body"></tbody>
            </table>
            <div>

            </div>
            <div class="paging-toolbar">
                <ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
            </div>
        </div>
    </div>
    <!--------------------------信息列表：带表格面板 end------------------------------------>

</div>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>

<script type="text/javascript">
    //新增保存数据
    function add() {
        var upOrderfile = $("#upOrderfile").val();
        if(upOrderfile==""||upOrderfile==null){
            alert("文件不能为空，请选择文件！");
            $("#upOrderfile").focus();
            return false;
        }
        //alert("ggg");
        //$("#addSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_order_goods/testexceladd?1=1&time="+Math.random();
        //直接提交表单；jquery $.ajax和$.post不能提交file的
        //你可以在页bai面放一个隐藏的iframe 然后du让表单提zhi交到这个iframe
        //alert("url="+url);
        ffAdd.action =  url;
        ffAdd.submit();
        $("#upOrderfile").val("");

        //result就是提bai交以后的返回值
        $('#hide_iframe').load(function(){
            var result = $(this).contents().find("body").text();
            //alert("result typeof ="+typeof result +";result="+result+";======result.result="+result.result);
            var data = JSON.parse(result);
            //alert("date json object="+data);
            if (data.result=="success") {
                //保存成功  1.关闭弹出层，
                showSuccessTips("恭喜保存成功!", "提示");
                //history.goBack();
                //1、重新初始化数据显示，把刚刚提交上传的excel数据展示出来；
                Search(0);
                return true;
            }
            else {
                //$("#addSaveButton").removeAttr("disabled");
                showErrorTips("保存数据失败!", "错误信息：");
                return false;
            }
        });
    }

    $().ready(function(){
        //1、初始化数据显示
        Search(0);

        //2、隐藏或者显示
        $("#shButton").click(function(){
            $("#shDiv").toggle();
            $("#qhDiv").toggleClass("icon-chevron-up icon-chevron-down");
        });

    }) //end funciton read;

    //根据查询条件，查询列表数据并显示
    function Search(startIndex){
        var good_num = $("#good_num").val();
        //alert("good_num="+good_num);
        if(good_num!=""||good_num!=null){
            if(isNaN(good_num)){
                alert("盘数请输入数字，不能输入非数字字符！");
                $("#good_num").focus();
                return false;
            }
        }
        //扫描打印
        var process_code = document.getElementById("process_code").value;

        var pageSize = document.getElementById("pageSize").value;
        var condition = $("#form1").serialize();
        var url = "<%=basePath%>t_order_goods/getAllT_order_goods?startIndex="+startIndex+"&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
        //alert(url);
        $.getJSON(url, function (data){
            //$("#pageSize").html(data.pageSize);
            $("#totalCount").html(data.totalCount);
            $("#totalPageNo").html(data.totalPageNo);
            $("#grid_body").html("");

            //item
            // 1: 客户名称 buyer_company_name 	2: PO/订单号 saller_tel	3:CPN/物料编码 buyer_tel
            // 4:MPN/规格型号 saller_company_address	  5:QTY/数量 ext1  6: BRAND/品牌 ext2
            // 7:供应商 saller_company_name	 8:盘数 good_num 	 9:辅助出货数量; ext3

            //1、表格行内容输出
            $.each(data.items, function(i,item){
                var str="<tr>";
                str+="<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='checkbox' value='"+item.order_goods_id+"'></td>";
                str+="<td>"+(i+1)+"</td>";
                str+="<td>"+doNull(item.buyer_company_name)+"</td>";
                str+="<td>"+doNull(item.saller_tel)+"</td>";
                str+="<td>"+doNull(item.buyer_tel)+"</td>";
                str+="<td>"+doNull(item.saller_company_address)+"</td>";
                str+="<td>"+doNull(item.ext1)+"</td>";
                str+="<td>"+doNull(item.ext2)+"</td>";
                str+="<td>"+doNull(item.saller_company_name)+"</td>";
                str+="<td>"+doNull(item.good_num)+"</td>";
                str+="<td>"+doNull(item.price)+"</td>";
                str+="<td>"+doNull(item.ext3)+"</td>";
                str+="<td>"+doNull(item.creater)+"</td>";
                str+="<td>"+doNull(item.creattime)+"</td>";
                str+="<td>"+doNull(item.updater)+"</td>";
                str+="<td>"+doNull(item.updatetime)+"</td>";
                if(item.status==0){
                    str+="<td><span class='label label-danger'>未扫描</span></td>";
                }else if(item.status==1){
                    str+="<td><span class='label label-danger'>部分扫描核销</span></td>";
                }else if(item.status==2){
                    str+="<td><span class='label label-success'>已扫描核销</span></td>";
                }else{
                    str+="<td><span class='label label-danger'>其它状态</span></td>";
                }
                str+="<td style='width:100px' >&nbsp;&nbsp;";
                if(process_code =='smdy'){
                    //str+="<a href='<%=basePath%>t_order_goods/toT_order_goodsCurd?oplx=view&id="+item.order_goods_id+"' class='text-danger'>&nbsp;&nbsp;<span class='glyphicon glyphicon-search' style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
                    if(item.status !='2') {
                        //str += "<a href='<%=basePath%>t_order_goods/toT_order_goodsSMDY?buyer="+item.buyer+"&oplx=edit&id=" + item.order_goods_id + "' class='text-danger'>&nbsp;&nbsp;<span class='icon-barcode'  style='color:rgb(0, 128, 255)'>扫描</span>&nbsp;&nbsp;</a>";
                    }
                    str+="<a href='<%=basePath%>t_order_goods/toT_order_goodsPrint?buyer="+item.buyer+"&oplx=edit&id="+item.order_goods_id+"' target='_blank' class='text-danger'>&nbsp;&nbsp;<span class='icon-print'  style='color:rgb(0, 128, 255)'>打印</span>&nbsp;&nbsp;</a>";
                    //str+="<a href='javascript:del("+item.order_goods_id+")' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span></a>&nbsp;&nbsp;";
                }

                str+="</td>";
                str+="</tr>";
                $("#grid_body").append(str);
            });//end each data;

            //2、分业处理
            var element = $("#grid_paging");
            if(data.totalCount>0){
                //第二种处理分页方案，直接生成分页html内容，然后.html()到目标对象；
                var pageHtml ="";
                pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.firstIndex+')">首页</button></li>';
                pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.previousIndex+')">上一页</button></li>';
                pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " >当前第  '+data.currentPageNo+' 页</button></li>';
                pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.nextIndex+')">下一页</button></li>';
                pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.lastIndex+')">尾页</button></li>';
                element.html(pageHtml);
            }else{
                element.html("");
            }
        })//end getJSON;
    }

    //通过选择单条记录，点击‘修改‘按钮进行查看
    function toEdits(){
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if(id!=false){
            self.location= "<%=basePath%>t_order_goods/toT_order_goodsCurd?oplx=edit&id="+id+"&time="+Math.random();
        }
    }

    //通过选择单条记录，点击‘查看‘按钮进行查看
    function toViews(){
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if(id!=false){
            self.location= "<%=basePath%>t_order_goods/toT_order_goodsCurd?oplx=view&id="+id+"&time="+Math.random();;
        }
    }

    //通过选择单条记录，点击‘删除‘按钮进行查看
    function getDel(){
        var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
        if(id!=false){
            del(id);
        }
    }

    //删除函数
    function del(id){
        var url = "<%=basePath%>t_order_goods/delT_order_goods?id=" + id+"&time="+Math.random();
        bootbox.confirm({
            size: 'small',
            buttons: {
                confirm: {
                    label: ' 删除 ',
                    className: 'btn btn-sm btn-danger'
                },
                cancel: {
                    label: '   取消     ',
                    className: 'btn btn-success btn-sm'
                }
            },
            message: '您确认要删除选中的记录？',
            callback: function(result) {
                if(result) {if(result){ myDel(url);}}
            },
            title:'删除记录提示：',
            className:' '
        })
    }
</script>
